package com.danco.training.zaneuskaya.domain;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "orders")
public class Order implements  Cloneable, Serializable {

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4525253790711647029L;
	
	
	@Id
	@GeneratedValue
	@Column(name = "O_ID")
	private int id;
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="order_book", joinColumns=@JoinColumn(name="ORDER_ID", referencedColumnName="O_ID"), inverseJoinColumns=@JoinColumn(name="BOOK_ID",  referencedColumnName="B_ID"))  
	private List<Book> books;
	
	@Column(name = "EXECUTED")
	private boolean executed;
	
	@Column(name = "ORDER_DATE")
	private Date orderDate;
	
	@Column (name ="TOTAL_PRICE")
	private double totalPrice;
	
	
	public Order() {}

	public Order(int id) {

		this.id = id;
		this.books = new ArrayList<Book>();
		this.executed = false;
		this.totalPrice = 0;
	}

	public Order(int id, List<Book> books, boolean executed, Date orderDate, double totalPrice) {
		this.executed = executed;
		this.id = id;
		this.books = books;
		this.orderDate = orderDate;
		this.totalPrice = totalPrice;
	}

	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<Book> getBooks() {
		return books;
	}

	public void setBooks(List<Book> books) {
		this.books = books;
	}

	public boolean isExecuted() {
		return executed;
	}

	public void setExecuted(boolean executed) {
		this.executed = executed;
	}

	public Date getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(Date orderDate) {
		this.orderDate = orderDate;
	}

	public double getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

	public Order clone() throws CloneNotSupportedException {

		return (Order) super.clone();

	}

}
